Ti.include('config.js');

if( !Ti.App.Properties.hasProperty('firstClient') )
	Ti.App.Properties.setBool('firstClient', true);
if( !Ti.App.Properties.hasProperty('firstPro') )
	Ti.App.Properties.setBool('firstPro', true);
	
var win = Titanium.UI.currentWindow;
win.backgroundColor = 'red';

var welcomeMsgLabel = Titanium.UI.createLabel({
	text : '',
	top : 5,
	left : 5
});
win.add(welcomeMsgLabel);

var emptyView = Titanium.UI.createView({});
win.leftNavButton = emptyView;

var clientBtn = Titanium.UI.createButton({
	title : 'Fitness Client',
	top : 160,
	width : 120
});

win.add(clientBtn);
clientBtn.addEventListener('click', clickListner);

var proBtn = Titanium.UI.createButton({
    title : 'Fitness Professional',
    top : 210,
    width : 160
});

win.add(proBtn);
proBtn.addEventListener('click', clickListner);

// Create a Label.
var aLabel = Ti.UI.createLabel({
    text : 'Discover your fitawsome by selecting what you are',
    
    height : 50,
    width : 200,
    top : 80,
    textAlign : 'left'
});

// Add to the parent view.
win.add(aLabel);

function clickListner(e) {
	var winTitle;
	if (e.source.title == 'Fitness Client'){
		Ti.App.user = 'client';
		winTitle = 'Fit-Awesome';
	}
	else if (e.source.title == 'Fitness Professional'){
		Ti.App.user = 'pro';
		winTitle = 'Login to unleash the awesomeness';
	}

	set_user_credentials('type', Ti.App.user);

	var newWin = Titanium.UI.createWindow({
		title : winTitle,
		url : 'login.js',
		backgroundColor : 'white'
	});

	Ti.UI.currentTab.open(newWin, {
		model : true
	});
}